<?php
/**
 * PHP Class
 *
 * LICENSE
 *
 * Processing: Page
 *
 * @category   	Gnn Cms
 * @package    	Gnn 
 * @copyright  	Copyright vinanewstar.vn@gmail.com
 * @author		GiangNam (vinanewstar.vn@gmail.com)
 * @license    	GNU General Public License Version 2 or later (the "GPL")
 * @version     v1.0 Jun 5, 2013 || 10:01:14 AM
 */
class Zendvn_Page{
	public $id;
	public $title;
	public $alias;
	public $note;
	public $published;
	public $component_id;
	public $component_control;
	public $component_action;
	public $checked_out;
	public $checked_out_time;
	public $access;
	public $template_style_id;
	public $home;
	public $client_id;
	public $ordering;
	public $metakey;
	public $metadesc;
	public $content_type;
	
	public function __construct($id, $client_id = 1){
		$this->_loadPage($id, $client_id);
	}
	
	/**
	 * load module from database
	 * @param integer $id
	 */
	private function _loadPage($id, $client_id){
		$db = Zend_Registry::get(REGISTRY_KEY_DBO);
		if($id != 0)
			// load page by id
			$sql = $db  ->select()
						->from(TBL_PRF."page")
						->where("id = ?",$id);
		else 
			// load home page
			$sql = $db  ->select()
						->from(TBL_PRF."page")
						->where("client_id = ?",$client_id)
						->where("home = 1");
		$page = $db->fetchRow($sql);
	
		$this->id 							= $page['id'];
		$this->title 						= $page['title'];
		$this->alias 						= $page['alias'];
		$this->note 						= $page['note'];
		$this->access 						= $page['access'];
		$this->checked_out 					= $page['checked_out'];
		$this->checked_out_time 			= $page['checked_out_time'];
		$this->client_id 					= $page['client_id'];
		$this->component_id 				= $page['component_id'];
		$this->component_action 			= $page['component_action'];
		$this->component_control 			= $page['component_control'];
		$this->home 						= $page['home'];
		$this->ordering 					= $page['ordering'];
		$this->published 					= $page['published'];
		$this->metadesc 					= $page['metadesc'];
		$this->metakey 						= $page['metakey'];
		$this->template_style_id 			= $page['template_style_id'];
		$this->content_type 				= $page['content_type'];
	}
	
	public function loadHeadInfo($view){
		$view->headMeta()->appendHttpEquiv("Content-Type", $this->content_type);
		$view->headTitle()->append($this->title." ");
		$view->headMeta()->appendName("keywords",$this->metakey." ");
		$view->headMeta()->appendName("description",$this->metadesc." ");
	}
}